<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="en" ng-app="app">

<head>
    <meta charset="utf-8" />
    <title>行业资讯</title>
    <meta name="description" content="app, web app, responsive, responsive layout, admin, admin panel, admin dashboard, flat, flat ui, ui kit, AngularJS, ui route, charts, widgets, components" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <%--<link rel="stylesheet" href="${pageContext.request.contextPath}/static/angular/css/bootstrap.css" type="text/css" />--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/angular/css/buttons.css" type="text/css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/multiple-select/multiple-select.css" type="text/css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/multiple-select/demos/assets/bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap-fileinput/css/fileinput.min.css"/>

    <script src="${pageContext.request.contextPath}/static/angular/js/angular.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/angular/controll/client-list.js"></script>
    <script src="${pageContext.request.contextPath}/static/multiple-select/demos/assets/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/multiple-select/multiple-select.js"></script>

    <!--fileinput-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap-fileinput/css/fileinput.min.css"/>
    <script src="${pageContext.request.contextPath}/static/bootstrap-fileinput/js/fileinput.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/bootstrap-fileinput/js/locales/zh.js"></script>


    <script src="${pageContext.request.contextPath}/static/angular/vendor/jquery/bootstrap.js"></script>


    <script type="text/javascript" src="${pageContext.request.contextPath}/static/jslib/syUtils.js"></script>



    <script>

        function getScope() {
            var appElement = document.querySelector('[ng-controller=client-ctrl]');
            //获取$scope变量
            var $scope = angular.element(appElement).scope();
            //上一行改变了msg的值，如果想同步到Angular控制器中，则需要调用$apply()方法即可
            // $scope.$apply();
            //调用控制器中的getData()方法
            // console.log($scope.getData());
            return $scope;
        }

        //初始化fileinput控件（第一次初始化）
        function initFileInput(ctrlName, uploadUrl) {
            var control = $('#' + ctrlName);

            var extra = '';
            var key = '';
            var imageUrl = '';
            control.fileinput({
                language: 'zh', //设置语言
                uploadUrl: uploadUrl, //上传的地址
                allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀
                showUpload: true, //是否显示上传按钮
                showCaption: false,//是否显示标题
                browseClass: "btn btn-primary", //按钮样式
                initialPreviewConfig:[],
                previewFileIcon: "<i  class='glyphicon glyphicon-king'></i>",
            }).     on("fileuploaded", function(event, data) {
                if(data.response)
                {
                    alert('上传处理成功');
                    var d = data.response['initialPreviewConfig'];
                    var d2 = d[0];
                    imageUrl = d2['caption'];
                    getScope().reviewImage = imageUrl;
//                    getScope().addValue = imageUrl;
//                    getScope().editValue = imageUrl;
//                    $('#addValue').val(imageUrl);
//                    $('#editValue').val(imageUrl);
                    extra = d2['extra'];
                    key = d2['key'];
                    //getScope().myAddImageUrl = imageUrl;

                }
            })
                .on('fileclear', function(event) {
                    var param = {};
                    param['fileName'] = key;
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url : "/file/delete",
                        data:  param,
                        async: false,
                        error: function(request) {
                            alert("Connection error");
                        },
                        success: function(data) {
                            $("#commonLayout_appcreshi").parent().html(data);
                            $('#addValue').val('');
                            $('#editValue').val('');
                        }
                    });
                })
        }

        $(function () {
            initFileInput("addImageUrl",getRootPath() + "/file/upload");
        })
    </script>

    <script>
        $(function () {
            initFileInput("editImageUrl",getRootPath() + "/file/upload");
        })
    </script>
</head>

<body  ng-controller="client-ctrl" style="height: auto">
    <!--查询-->
    <div class="col-md-12" >
        <div class="panel panel-default">
            <div class="panel-heading">查询</div>
            <div class="panel-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label for="queryKey" class="col-md-1 control-label">姓名</label>
                        <div class="col-md-2">
                            <input type="text" class="form-control" id="queryKey"  ng-model="queryKey">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="queryKey" class="col-md-1 control-label"></label>
                        <div class="col-md-2">
                            <button class="btn " ng-click="query()">搜索</button>

                            <button class="btn " ng-click="initPage()">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!--查询结束-->

    <!--按钮组-->
    <%--<div class="col-md-12" style="margin-bottom:20px;">--%>
        <%--<div class="button-group">--%>
            <%--<button type="button" class="button button-pill" ng-click="initAddModel()" data-toggle="modal" data-target="#clientModal">添加资讯</button>--%>
        <%--</div>--%>
    <%--</div>--%>
    <!--按钮组结束-->

    <!--图片模态框-->
    <div class="modal fade" id="showModal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document" style="width: 800px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">图片</h4>
                </div>
                <div class="modal-body">
                    <img id="myImage" src="" style="width:750px "/>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <!--展示模态框-->
    <div class="modal fade" id="showContent" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document" style="width: 800px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">内容</h4>
                </div>
                <div class="modal-body">
                    <p id="viewContent"></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <!--展示模态框-->
    <div class="modal fade" id="showQuestion" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document" style="width: 800px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">提问</h4>
                </div>
                <div class="modal-body">
                    <p id="viewQuestion"></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <!--内容模态框-->
    <div class="modal fade" id="clientModal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document" style="width: 1000px">
            <div class="modal-content">
                <div class="modal-header" style="width: 1000px">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">信息</h4>
                </div>
                <div class="modal-body">
                    <form name="editForm" class="form-horizontal">
                        <div class="form-group">
                            <label for="title" class="col-sm-1 control-label">标题</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" id="title" ng-model="title">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="summary" class="col-sm-1 control-label">摘要</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" id="summary" ng-model="summary">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="priority" class="col-sm-1 control-label">排序</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" id="priority" ng-model="priority">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="priority" class="col-sm-1 control-label">内容</label>
                            <div class="col-sm-11">
                                <script id="editor" type="text/plain">

                                </script>
                            </div>
                        </div>
                        <div class="form-group" style="height: 500px">
                            <label for="addImageUrl" class="col-sm-1 control-label">图片</label>
                            <div class="col-sm-11" style="height: 340px;">
                                <input id="addImageUrl" name="file" ng-model="addImageUrl" class="form-control" type="file">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" ng-click="submit()">提交</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->




    <!--表格-->
    <div class="col-md-12" style="height: 100%">
        <div class="panel panel-default">
            <div class="panel-heading">列表</div>
            <div class="panel-body">
                <table class="table table-hover ">
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>联系电话</th>
                        <th>email</th>
                        <th>提问</th>
                        <th>创建时间</th>
                        <%--<th>操作</th>--%>
                    </tr>
                    <tr ng-repeat="item in clientList">
                        <td>
                            {{ $index + 1 + ((page.cpage-1) * 10)}}
                        </td>
                        <td style="font-size: smaller">{{item.name}}</td>
                        <td style="font-size: smaller">{{item.contract}}</td>
                        <td style="font-size: smaller">{{item.email}}</td>
                        <td style="font-size: smaller " ng-click="viewQuestion(item.question)">{{item.question | subQuestion}}</td>
                        <td style="font-size: smaller">{{item.createTime | date : 'yyyy-MM-dd HH:mm:ss'}}</td>
                        <%--<td>--%>
                            <%--<button type="button" class="button button-action button-box"   ng-click="setClientInfo(item)"><i class="glyphicon glyphicon-edit"></i></button>--%>
                            <%--<button class="button button-caution button-box" ng-click="deleteOneClient(item.id)"><i class="glyphicon glyphicon-trash"></i></button>--%>
                        <%--</td>--%>
                    </tr>
                </table>
            </div>

        </div>
        <div class="col-md-12">
            <div style="float: left;">
                <span>共{{page.count}}条记录 ，当前第{{page.cpage}}页/共{{page.totalnum}}页</span>
            </div>
            <div style="float: right;">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <li ng-click="pageclick('«')">
                            <a href="#" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <li ng-class="{'active':page.cpage == item}" ng-repeat="item in page.pagenum" ng-click="pageclick(item)"><a  href="#" ng-bind="item"></a></li>
                        
                        <li ng-click="pageclick('»')">
                            <a href="#" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>

    <!-- 配置文件 -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('editor');

        function getContent() {
            var params = {};
            params['content'] = UE.getEditor('editor').getContent()
            return params
        }

        function setContent(detail) {
            ue.setContent(detail);
        }
    </script>
</body>

</html>
